package com.zmj.sy.mom.srv.aps.service;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.zmj.sy.mom.srv.aps.bean.entity.resource.*;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.shifttype.ShiftTypePubReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.stationweekday.StationWeekdayGetResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.weekdayscheme.*;
import com.zmj.sy.mom.srv.aps.mapper.*;
import com.zmj.sy.mom.srv.aps.utils.MkBeanUtils;
import com.zmj.sy.mom.srv.aps.utils.ProjectConstants;
import com.zmj.sy.mom.srv.aps.utils.SyExceptionUtils;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;


@RequiredArgsConstructor
@Service
public class WeekdaySchemeService {

    private final WeekdaySchemeMapper weekdaySchemeMapper;

    private final ShiftMapper shiftMapper;
    private final ShiftTypeMapper shiftTypeMapper;
    private final WeekdayRuleMapper weekdayRuleMapper;

    private final WeekdayMapper weekdayMapper;
    private final StationWeekdaySchemeMapper stationWeekdaySchemeMapper;

    private final StationWeekdayRuleMapper stationWeekdayRuleMapper;

    @SneakyThrows
    @Transactional(rollbackFor = Exception.class)
    public Integer add(WeekdaySchemeAddReqVo reqVo) {
        // 简化模式必须校验星期规则，必须有周一到周日
        List<Integer> collect1 = reqVo.getRuleList().stream().filter(e -> e.getType() == 4).map(e -> Integer.valueOf(e.getValue())).sorted().collect(Collectors.toList());
        if (collect1.size() != 7) {
            throw SyExceptionUtils.e("简化模式必须有周一到周日");
        }
        if (collect1.get(0) != 1) {
            throw SyExceptionUtils.e("必须从星期一开始");
        }


        WeekdayScheme weekdayScheme = MkBeanUtils.copyProperties(reqVo, WeekdayScheme.class);
        weekdayScheme.setType(2);
        weekdaySchemeMapper.insert(weekdayScheme);

        List<WeekdayRule> collect = reqVo.getRuleList()
                .stream()
                .map(e -> MkBeanUtils.copyProperties(e, WeekdayRule.class))
                .collect(Collectors.toList());
        for (WeekdayRule weekdayRule : collect) {
            weekdayRule.setWeekdaySchemeId(weekdayScheme.getId());
            weekdayRuleMapper.insert(weekdayRule);
        }
        return weekdayScheme.getId();

    }

  /*  @Transactional

    public void pub(BaseIdReqVo reqVo) {

        WeekdayScheme scheme = weekdaySchemeMapper.selectById(reqVo.getId());
        LocalDate startDate = scheme.getStartDate();
        LocalDate endDate = scheme.getEndDate();

        // 先删除这个日期上的所有日历
        weekdayMapper.delete(Wrappers.<Weekday>lambdaQuery().between(Weekday::getShiftDay, startDate, endDate));

        // 日历和班次打散
        List<Weekday> allWeekday = getWeekdays(scheme);

        // 保存
        for (Weekday weekday : allWeekday) {
            weekdayMapper.insert(weekday);
        }
    }
*/


 /*   public List<Weekday> getWeekdays(WeekdayScheme scheme) {
        LocalDate startDate = scheme.getStartDate();
        LocalDate endDate = scheme.getEndDate();
        List<Shift> shifts = shiftMapper.selectList(Wrappers.<Shift>lambdaQuery().eq(Shift::getShiftTypeId, scheme.getShiftTypeId()));
        List<WeekdayRule> ruleList = weekdayRuleMapper.selectList(Wrappers.<WeekdayRule>lambdaQuery().eq(WeekdayRule::getWeekdaySchemeId, scheme.getId()));

        List<Weekday> allWeekday = Stream
                .iterate(startDate, s -> s.plusDays(1))
                .limit(startDate.until(endDate, ChronoUnit.DAYS) + 1)
                .flatMap(e ->
                        shifts.stream()
                                .map(shift -> {
                                    Weekday newDay = new Weekday();
                                    MkBeanUtils.copyPropertiesIgnore(shift, newDay);
                                    newDay.setShiftDay(e);
                                    newDay.setShiftSeq(shift.getSeq());
                                    newDay.setShiftId(shift.getId());
                                    return newDay;
                                })
                )
                .collect(Collectors.toList());

        // 匹配规则，可以抽成策略模式，数据量大，为了效率不建议
        for (Weekday w : allWeekday) {
            for (WeekdayRule weekdayRule : ruleList) {
                if (weekdayRule.getType() == 4) {
                    if (weekdayRule.getValue().equals(String.valueOf(w.getShiftDay().getDayOfWeek().getValue()))) {
                        w.setDateType(weekdayRule.getDateType());
                        w.setWorkState(weekdayRule.getStatus());
                        w.setWeekdayRuleId(weekdayRule.getId());
                    }
                } else if (weekdayRule.getType() == 3) {
                    if (LocalDate.parse(weekdayRule.getValue(), DatePattern.NORM_DATE_FORMATTER).equals(w.getShiftDay())) {
                        w.setDateType(weekdayRule.getDateType());
                        w.setWorkState(weekdayRule.getStatus());
                        w.setText(weekdayRule.getText());
                        w.setWeekdayRuleId(weekdayRule.getId());
                    }
                } else if (weekdayRule.getType() == 2) {
                    String value = weekdayRule.getValue();
                    String[] split = value.split(ProjectConstants.WEEKDAY_RULE_WEEKVALUE_SPLIT);
                    if (split[0].equals(w.getShiftDay().toString()) && split[1].equals(String.valueOf(w.getShiftId()))) {
                        w.setDateType(weekdayRule.getDateType());
                        w.setWorkState(weekdayRule.getStatus());
                        w.setText(weekdayRule.getText());
                        w.setWeekdayRuleId(weekdayRule.getId());
                    }
                } else if (weekdayRule.getType() == 1){
                    String value = weekdayRule.getValue();
                    String[] split = value.split(ProjectConstants.WEEKDAY_RULE_WEEKVALUE_SPLIT);
                    LocalDate start = LocalDate.parse(split[0], DatePattern.NORM_DATE_FORMATTER);
                    LocalDate end = LocalDate.parse(split[1], DatePattern.NORM_DATE_FORMATTER);
                    if (w.getShiftDay().compareTo(start) >= 0 && w.getShiftDay().compareTo(end) <= 0) {
                        w.setDateType(weekdayRule.getDateType());
                        w.setWorkState(weekdayRule.getStatus());
                        w.setText(weekdayRule.getText());
                        w.setWeekdayRuleId(weekdayRule.getId());
                    }

                }
            }
        }
        return allWeekday;
    }*/

    @Transactional
    public void templateAdd(WeekdaySchemeTemplateAddReqVo reqVo) {
        // 新增班制类型
        ShiftType shiftType = new ShiftType();
        shiftType.setName(reqVo.getName());
        shiftType.setMyCode(reqVo.getName());
        shiftType.setStartDate(reqVo.getStartDate());
        shiftType.setEndDate(reqVo.getEndDate());
        shiftTypeMapper.insert(shiftType);
        // 新增日历类型
//        WeekdayScheme weekdayScheme = MkBeanUtils.copyProperties(reqVo, WeekdayScheme.class);
//        weekdayScheme.setType(1);
//        weekdayScheme.setShiftTypeId(shiftType.getId());
//        weekdaySchemeMapper.insert(weekdayScheme);
        if(reqVo.getRuleList() == null || reqVo.getRuleList().isEmpty()){
            reqVo.setRuleList(getDefaultRuleList());
        }

        List<WeekdayRule> collect = reqVo.getRuleList()
                .stream()
                .map(e -> MkBeanUtils.copyProperties(e, WeekdayRule.class))
                .collect(Collectors.toList());
        for (WeekdayRule weekdayRule : collect) {
            weekdayRule.setShiftTypeId(shiftType.getId());
            weekdayRuleMapper.insert(weekdayRule);
        }
    }

    private List<WeekdaySchemeAddRuleReqVo> getDefaultRuleList() {
        return Lists.newArrayList(
                new WeekdaySchemeAddRuleReqVo(4, 1, "星期一", "1", 1, 1),
                new WeekdaySchemeAddRuleReqVo(4, 2, "星期二", "2", 1, 1),
                new WeekdaySchemeAddRuleReqVo(4, 3, "星期三", "3", 1, 1),
                new WeekdaySchemeAddRuleReqVo(4, 4, "星期四", "4", 1, 1),
                new WeekdaySchemeAddRuleReqVo(4, 5, "星期五", "5", 1, 1),
                new WeekdaySchemeAddRuleReqVo(4, 6, "星期六", "6", 2, 1),
                new WeekdaySchemeAddRuleReqVo(4, 7, "星期日", "7", 2, 2)
        );
    }

    public BaseListResVo<WeekdaySchemeTemplateListResVo> templateList() {

//        List<WeekdayScheme> weekdaySchemes = weekdaySchemeMapper.selectList(Wrappers.<WeekdayScheme>lambdaQuery().eq(WeekdayScheme::getType, 1));
//        if (weekdaySchemes == null || weekdaySchemes.size() < 1) {
//            return BaseListResVo.of(weekdaySchemes, WeekdaySchemeTemplateListResVo.class);
//        }



//        List<Integer> ids = weekdaySchemes.stream().map(WeekdayScheme::getId).collect(Collectors.toList());

        List<ShiftType> shiftTypeList = shiftTypeMapper.selectList(null);
        List<Integer> ids = shiftTypeList.stream().map(ShiftType::getId).collect(Collectors.toList());


        List<WeekdayRule> ruleList = weekdayRuleMapper.selectList(Wrappers.<WeekdayRule>lambdaQuery().in(WeekdayRule::getShiftTypeId, ids));
        Map<Integer, List<WeekdayRule>> collect = ruleList.stream().collect(Collectors.groupingBy(WeekdayRule::getShiftTypeId));

        BaseListResVo<WeekdaySchemeTemplateListResVo> resVo = BaseListResVo.of(shiftTypeList, WeekdaySchemeTemplateListResVo.class);
        for (WeekdaySchemeTemplateListResVo datum : resVo.getData()) {
            List<WeekdayRule> weekdayRules = collect.get(datum.getId());
            datum.setShiftTypeId(datum.getId());
            if (weekdayRules != null) {
                weekdayRules.sort(Comparator.comparingInt(WeekdayRule::getSeq));
                datum.setRuleList(weekdayRules.stream().map(e -> MkBeanUtils.copyProperties(e, WeekdaySchemeAddRuleReqVo.class)).collect(Collectors.toList()));
            }
        }
        return resVo;
    }

    public List<WeekdaySchemeTimeRangeResVo> timeRange(WeekdaySchemeTimeRangeReqVo reqVo) {
//        WeekdayScheme scheme = weekdaySchemeMapper.selectById(reqVo.getId());

        ShiftType shiftType = shiftTypeMapper.selectById(reqVo.getId());

        LocalDate startDate = reqVo.getStart().minusMonths(3);
        LocalDate endDate = shiftType.getEndDate();
        //  班次
        List<Shift> shifts = shiftMapper.selectList(Wrappers.<Shift>lambdaQuery().eq(Shift::getShiftTypeId, shiftType.getId()));
        if(shifts.isEmpty()){
            throw SyExceptionUtils.e("该方案没有班制，请先配置班制");
        }

        //  周计划
        List<WeekdayRule> ruleList = weekdayRuleMapper.selectList(Wrappers.<WeekdayRule>lambdaQuery().eq(WeekdayRule::getShiftTypeId, shiftType.getId()));
        if(ruleList.isEmpty()){
            throw SyExceptionUtils.e("该方案的周配置被删除，请联系管理员或者删除后重新添加");
        }
        //  生成日历信息
        List<WeekdaySchemeTimeRangeResVo> allWeekday = Stream
                .iterate(startDate, s -> s.plusDays(1))
                .limit(startDate.until(endDate, ChronoUnit.DAYS) + 1)
                .map(e -> {
                    WeekdaySchemeTimeRangeResVo newDay = new WeekdaySchemeTimeRangeResVo();
                    newDay.setShiftDay(e);

                    for (Shift shift : shifts) {
                        WeekdaySchemeTimeRangeItemResVo item  = new WeekdaySchemeTimeRangeItemResVo();
                        item.setShiftSeq(shift.getSeq());
                        item.setOffsetStartDay(shift.getOffsetStartDay());
                        item.setOffsetEndDay(shift.getOffsetEndDay());
                        item.setStartTime(shift.getStartTime());
                        item.setEndTime(shift.getEndTime());
                        item.setShiftId(shift.getId());
                        newDay.getItem().add(item);
                    }
                    return newDay;
                })
                .collect(Collectors.toList());

        // 匹配规则，可以抽成策略模式，数据量大，为了效率不建议
        for (WeekdaySchemeTimeRangeResVo w : allWeekday) {
            for (WeekdayRule weekdayRule : ruleList) {
                if (weekdayRule.getType() == 3) {
                    if (LocalDate.parse(weekdayRule.getValue(), DatePattern.NORM_DATE_FORMATTER).equals(w.getShiftDay())) {
                        w.setDateType(weekdayRule.getDateType());
                        w.setWorkState(weekdayRule.getStatus());
                        w.setText(weekdayRule.getText());
                    }


                } else if (weekdayRule.getType() == 1){
                    String value = weekdayRule.getValue();
                    String[] split = value.split(ProjectConstants.WEEKDAY_RULE_WEEKVALUE_SPLIT);
                    LocalDate start = LocalDate.parse(split[0], DatePattern.NORM_DATE_FORMATTER);
                    LocalDate end = LocalDate.parse(split[1], DatePattern.NORM_DATE_FORMATTER);
                    if (!w.getShiftDay().isBefore(start) && !w.getShiftDay().isAfter(end)) {
                        w.setDateType(weekdayRule.getDateType());
                        w.setWorkState(weekdayRule.getStatus());
                        w.setText(weekdayRule.getText());
                    }


                }else if (weekdayRule.getType() == 4) {
                        if (weekdayRule.getValue().equals(String.valueOf(w.getShiftDay().getDayOfWeek().getValue()))) {
                            w.setDateType(weekdayRule.getDateType());
                            w.setWorkState(weekdayRule.getStatus());
                        }
                } else if (weekdayRule.getType() == 2) {
                    String value = weekdayRule.getValue();
                    String[] split = value.split(ProjectConstants.WEEKDAY_RULE_WEEKVALUE_SPLIT);
                    if(w.getShiftDay().equals(LocalDate.parse(split[0], DatePattern.NORM_DATE_FORMATTER))){
                        w.getItem().stream().filter(e -> e.getShiftId().equals(Integer.valueOf(split[1]))).findFirst().ifPresent(e -> {
                            e.setWorkState(weekdayRule.getStatus());
                            e.setText(weekdayRule.getText());
                        });
                    }
/*

                    w.setDateType(weekdayRule.getDateType());
                    w.setWorkState(weekdayRule.getStatus());
                    w.getItem().stream().filter(e->e.getShiftId().equals(Integer.valueOf(split[1]))).findFirst().ifPresent(e->{
                        e.setWorkState(weekdayRule.getStatus());
                        e.setText(weekdayRule.getText());
                    });
*/

                }
            }
        }

        //  每天上下班情况
        Map<LocalDate, WeekdaySchemeTimeRangeResVo> collect1 = allWeekday.stream().collect(Collectors.toMap(e -> e.getShiftDay(), e -> e));

        // 获取日内计划
        List<WeekdaySchemeTimeRangeResVo> resVoList = Stream.iterate(reqVo.getStart(), e -> e.plusDays(1L))
                .limit(reqVo.getStart().until(reqVo.getEnd(), ChronoUnit.DAYS) + 1)
                .filter(e -> collect1.containsKey(e))
                .map(e -> {
                    WeekdaySchemeTimeRangeResVo r = new WeekdaySchemeTimeRangeResVo();
                    r.setShiftDay(e);
                    WeekdaySchemeTimeRangeResVo weekdaySchemeTimeRangeResVo = collect1.get(e);
                    r.setWorkState(weekdaySchemeTimeRangeResVo.getWorkState());
                    r.setText(weekdaySchemeTimeRangeResVo.getText());
                    r.setDateType(weekdaySchemeTimeRangeResVo.getDateType());
                    List<WeekdaySchemeTimeRangeItemResVo> collect =new LinkedList<>();
                    List<WeekdaySchemeTimeRangeItemResVo> items = weekdaySchemeTimeRangeResVo.getItem();
                    for(WeekdaySchemeTimeRangeItemResVo item: items){
                        if(!ObjectUtils.isEmpty(item.getWorkState()) && !item.getWorkState().equals(r.getWorkState())){
                            collect.add(item);
                        }
                    }
                    r.setItem(collect);
                    return r;
                })
                .collect(Collectors.toList());

        return resVoList;

    }

    @Transactional
    public void templateEdit(WeekdaySchemeTemplateEditReqVo reqVo) {
//        WeekdayScheme weekdayScheme = weekdaySchemeMapper.selectById(reqVo.getId());
//        weekdayScheme.setName(reqVo.getName());
//        weekdayScheme.setShiftTypeId(reqVo.getShiftTypeId());
//        weekdaySchemeMapper.updateById(weekdayScheme);

        weekdayRuleMapper.delete(Wrappers.<WeekdayRule>lambdaQuery() .eq(WeekdayRule::getShiftTypeId, reqVo.getId()).eq(WeekdayRule::getType, 4));

        ShiftType shiftType = shiftTypeMapper.selectById(reqVo.getShiftTypeId());
        shiftType.setName(reqVo.getName());
        shiftType.setStartDate(reqVo.getStartDate());
        shiftType.setEndDate(reqVo.getEndDate());
        shiftTypeMapper.updateById(shiftType);


        if(reqVo.getRuleList() == null || reqVo.getRuleList().isEmpty()){
            reqVo.setRuleList(getDefaultRuleList());
        }

        List<WeekdayRule> collect = reqVo.getRuleList()
                .stream()
                .filter(e -> e.getType() == 4)
                .map(e -> MkBeanUtils.copyProperties(e, WeekdayRule.class))
                .collect(Collectors.toList());



        for (WeekdayRule weekdayRule : collect) {
//            weekdayRule.setWeekdaySchemeId(weekdayScheme.getId());
            weekdayRule.setShiftTypeId(reqVo.getShiftTypeId());
            weekdayRuleMapper.insert(weekdayRule);
        }

//        List<StationWeekdayScheme> list = stationWeekdaySchemeMapper.lambdaQuery().eq(StationWeekdayScheme::getSchemeId, reqVo.getId()).list();
//        for (StationWeekdayScheme stationWeekdayScheme : list){
//            stationWeekdayRuleMapper.delete(Wrappers.<StationWeekdayRule>lambdaQuery().eq(StationWeekdayRule::getStationId, stationWeekdayScheme.getStationId()).eq(StationWeekdayRule::getType, 4));
//            List<StationWeekdayRule> stationCollect = reqVo.getRuleList()
//                    .stream().filter(e -> e.getType() == 4)
//                    .map(e -> MkBeanUtils.copyProperties(e, StationWeekdayRule.class))
//                    .collect(Collectors.toList());
//            for (StationWeekdayRule weekdayRule : stationCollect) {
//                weekdayRule.setStationWeekdaySchemeId(weekdayScheme.getId());
//                weekdayRule.setStationId(stationWeekdayScheme.getStationId());
//                stationWeekdayRuleMapper.insert(weekdayRule);
//            }
//        }



    }


    @Transactional
    public void templateEdit2(WeekdaySchemeTemplateEditReqVo reqVo) {
//        WeekdayScheme weekdayScheme = weekdaySchemeMapper.selectById(reqVo.getId());
//        weekdayScheme.setName(reqVo.getName());
//        weekdayScheme.setShiftTypeId(reqVo.getShiftTypeId());
//        weekdaySchemeMapper.updateById(weekdayScheme);

        weekdayRuleMapper.delete(Wrappers.<WeekdayRule>lambdaQuery() .eq(WeekdayRule::getWeekdaySchemeId, reqVo.getId()).eq(WeekdayRule::getType, 4));

        if(reqVo.getRuleList() == null || reqVo.getRuleList().isEmpty()){
            reqVo.setRuleList(getDefaultRuleList());
        }

        List<WeekdayRule> collect = reqVo.getRuleList()
                .stream()
                .filter(e -> e.getType() == 4)
                .map(e -> MkBeanUtils.copyProperties(e, WeekdayRule.class))
                .collect(Collectors.toList());



        for (WeekdayRule weekdayRule : collect) {
//            weekdayRule.setWeekdaySchemeId(weekdayScheme.getId());
            weekdayRule.setShiftTypeId(reqVo.getShiftTypeId());
            weekdayRuleMapper.insert(weekdayRule);
        }

//        List<StationWeekdayScheme> list = stationWeekdaySchemeMapper.lambdaQuery().eq(StationWeekdayScheme::getSchemeId, reqVo.getId()).list();
//        for (StationWeekdayScheme stationWeekdayScheme : list){
//            stationWeekdayRuleMapper.delete(Wrappers.<StationWeekdayRule>lambdaQuery().eq(StationWeekdayRule::getStationId, stationWeekdayScheme.getStationId()).eq(StationWeekdayRule::getType, 4));
//            List<StationWeekdayRule> stationCollect = reqVo.getRuleList()
//                    .stream().filter(e -> e.getType() == 4)
//                    .map(e -> MkBeanUtils.copyProperties(e, StationWeekdayRule.class))
//                    .collect(Collectors.toList());
//            for (StationWeekdayRule weekdayRule : stationCollect) {
//                weekdayRule.setStationWeekdaySchemeId(weekdayScheme.getId());
//                weekdayRule.setStationId(stationWeekdayScheme.getStationId());
//                stationWeekdayRuleMapper.insert(weekdayRule);
//            }
//        }



    }

    @Transactional
    public void delete(BaseIdReqVo reqVo) {
        weekdaySchemeMapper.deleteById(reqVo.getId());
    }

    public void pubScheme(ShiftTypePubReqVo reqVo) {
            // 简化模式必须校验星期规则，必须有周一到周日
   /*         List<Integer> collect1 = reqVo.getRuleList().stream().filter(e -> e.getType() == 4).map(e -> Integer.valueOf(e.getValue())).sorted().collect(Collectors.toList());
            if (collect1.size() != 7) {
                throw SyExceptionUtils.e("简化模式必须有周一到周日");
            }
            if (collect1.get(0) != 1) {
                throw SyExceptionUtils.e("必须从星期一开始");
            }*/
        for (Integer shiftTypeId : reqVo.getIds()){
            weekdayRuleMapper.delete(Wrappers.<WeekdayRule>lambdaQuery().eq(WeekdayRule::getShiftTypeId, shiftTypeId).ne(WeekdayRule::getType, 4));

            List<WeekdayRule> collect = reqVo.getRuleList()
                    .stream().filter(e -> e.getType() != 4)
                    .map(e -> MkBeanUtils.copyProperties(e, WeekdayRule.class))
                    .collect(Collectors.toList());

            for (WeekdayRule weekdayRule : collect) {
                weekdayRule.setShiftTypeId(shiftTypeId);
                weekdayRuleMapper.insert(weekdayRule);
            }

//            List<StationWeekdayScheme> list = stationWeekdaySchemeMapper.lambdaQuery().eq(StationWeekdayScheme::getSchemeId, shiftTypeId).list();
//            stationWeekdayRuleMapper.delete(Wrappers.<StationWeekdayRule>lambdaQuery()
//                    .eq(StationWeekdayRule::getStationWeekdaySchemeId, shiftTypeId).ne(StationWeekdayRule::getType, 4));
//            List<StationWeekdayRule> stationCollect = reqVo.getRuleList()
//                    .stream().filter(e -> e.getType() != 4)
//                    .map(e -> MkBeanUtils.copyProperties(e, StationWeekdayRule.class))
//                    .collect(Collectors.toList());
//
//            for (StationWeekdayScheme stationWeekdayScheme : list){
//                // 简化模式必须校验星期规则，必须有周一到周日
//                for (StationWeekdayRule weekdayRule : stationCollect) {
//                    weekdayRule.setStationWeekdaySchemeId( shiftTypeId);
//                    weekdayRule.setStationId(stationWeekdayScheme.getStationId());
//                    stationWeekdayRuleMapper.insert(weekdayRule);
//                }
//            }

        }



    }

    public StationWeekdayGetResVo getWeekdayRule(BaseIdReqVo reqVo) {
//        WeekdayScheme scheme = weekdaySchemeMapper.selectOne(Wrappers.<WeekdayScheme>lambdaQuery().eq(WeekdayScheme::getId, reqVo.getId()));
//        if(scheme == null){
//            return new StationWeekdayGetResVo();
//        }
        ShiftType shiftType = shiftTypeMapper.selectById(reqVo.getId());
        StationWeekdayGetResVo resVo = MkBeanUtils.copyProperties(shiftType, StationWeekdayGetResVo.class);

        List<WeekdayRule> ruleList = weekdayRuleMapper.selectList(Wrappers.<WeekdayRule>lambdaQuery().eq(WeekdayRule::getShiftTypeId, reqVo.getId()));
        ruleList.sort(Comparator.comparingInt(WeekdayRule::getSeq));
        resVo.setRuleList(ruleList.stream().map(e -> MkBeanUtils.copyProperties(e, WeekdaySchemeAddRuleReqVo.class)).collect(Collectors.toList()));

        return resVo;

    }
}
